package demo1.service.impl;

import demo1.dao.AccountDao;
import demo1.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
@Primary//通过类型获取时，只能获取这一个
public class AccountServiceImpl_two implements AccountService {
    @Autowired
    AccountDao dao;


    @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.READ_COMMITTED,rollbackFor = Exception.class,timeout = 3)
    public void transfer(String from, String to, Double money) {

        dao.update(from,-money);
        //int a=1/0;
        dao.update(to,money);

    }

    @Transactional(propagation = Propagation.REQUIRED,readOnly = true)
    public void query(String name) {
        //dao.update(name,10d);
        System.out.println(name+"的余额为："+dao.selectMoney(name));
    }
}
